use "E:\隨身硬碟備份\E\TRY\findev_2017\Fin_Co2_pol_2020\program\n82_4y_8417_renew.dta",clear
set more off 
mata: mata set matafavor speed, perm
tsset id period
drop if id==45
drop if id==76

egen free_a=mean(sc_right),   by(id)
egen fd_a=  mean(fin_dev),    by(id)
egen fs_a=  mean(fin_str),    by(id)
egen bon_a= mean(av_bon),     by(id)
egen ler_a= mean(av_lern),    by(id)
egen con_a= mean(lnav_concn), by(id)
egen hh_a=  mean(lnav_borhh), by(id)
egen fm_a=  mean(lnav_borfm), by(id)

tabstat free_a fd_a fs_a bon_a ler_a con_a hh_a fm_a, ///
stat(min p10 p25 p50 mean p75 p90 max)

**aggregate**

gen fd1_y=0 if id==67
replace fd1_y=0 if id==56
replace fd1_y=0 if id==12
replace fd1_y=0.0233   if id==13
replace fd1_y=-0.0203 if id==80
gen fd_1=0.4640 if id==67
replace fd_1=0.5355 if id==56
replace fd_1=0.6098 if id==12
replace fd_1=0.0038 if id==13
replace fd_1=1 if id==80

gen fs1_y=0 if id==7
replace fs1_y=0 if id==1
replace fs1_y=0 if id==27
replace fs1_y=-0.0157 if id==13
replace fs1_y=0.0198 if id==80
gen fs_1=0.3784 if id==7
replace fs_1=0.4412 if id==1
replace fs_1=0.5014 if id==27
replace fs_1=0.0038 if id==13
replace fs_1=1 if id==80


xtabond2 lnav_engpc c.fin_dev c.fin_dev#c.sc_right c.fin_str c.fin_str#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev, lag(1 1))                gmm(c.fin_dev#c.sc_right, lag(2 2) collapse) ///
gmm(c.fin_str, lag(2 2) orthogonal)     gmm(c.fin_str#c.sc_right, lag(2 2) collapse) ///
gmm(c.sc_right,lag(2 2) collapse) ///
gmm(c.lnav_gdp,lag(1 2))                gmm(c.lnav_gdp#c.lnav_gdp,lag(1 2)) ///  
iv(ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small
margins, dydx(c.lnav_gdp)
sum fin_dev fin_str sc_right lnav_gdp
tabstat sc_right, stat(p10 p25 p50 p75 p90 mean)

/*FD
找x軸的轉折點
margins, dydx(c.fin_dev) at(sc_right=(0.46735 (0.00001) 0.46736))
margins, dydx(c.fin_dev) at(sc_right=(0.61791 (0.00001) 0.61792))
找不同分位下的邊際效果
margins, dydx(c.fin_dev) at(sc_right=0.0038)
margins, dydx(c.fin_dev) at(sc_right=0.0479)
margins, dydx(c.fin_dev) at(sc_right=0.1739)
margins, dydx(c.fin_dev) at(sc_right=0.4412)
margins, dydx(c.fin_dev) at(sc_right=0.9444)
margins, dydx(c.fin_dev) at(sc_right=1)
margins, dydx(c.fin_dev) at(sc_right=0.5177)
*/

margins, dydx(c.fin_dev) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(b) Effect of findev on energy use") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5177, lcolor(red) lpattern(dash)) ///
ytitle("∂ energy use / ∂ findev") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0233 0.0012 -0.0203, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5177 0.4674 0.6179 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fd1_y fd_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0233  0.0038  "CHN", place(ne) size(small)) ///
text (0.0008 0.5177        , place(sw) size(small)) ///
text (0 0.4674       , place(sw) size(small)) ///
text (0 0.4640  "ZAF", place(sw) size(small)) ///
text (0 0.5355  "PAN", place(ne) size(small)) ///
text (0 0.6179       , place(ne) size(small)) ///
text (0 0.6098  "CHL", place(ne) size(small)) ///
text (-0.0203 1 "USA", place(s)  size(small))


/*FS
找x軸的轉折點
margins, dydx(c.fin_str) at(sc_right=(0.37350 (0.00001) 0.37351))
margins, dydx(c.fin_str) at(sc_right=(0.51035 (0.00001) 0.51036))
找不同分位下的邊際效果
margins, dydx(c.fin_str) at(sc_right=0.0038)
margins, dydx(c.fin_str) at(sc_right=0.0479)
margins, dydx(c.fin_str) at(sc_right=0.1739)
margins, dydx(c.fin_str) at(sc_right=0.4412)
margins, dydx(c.fin_str) at(sc_right=0.9444)
margins, dydx(c.fin_str) at(sc_right=1)
margins, dydx(c.fin_str) at(sc_right=0.5177)
*/

margins, dydx(c.fin_str) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(e) Effect of finstr on energy use") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5177, lcolor(red) lpattern(dash)) ///
ytitle("∂ energy use / ∂ finstr") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(-0.0157 0.0023 0.0198, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5177 0.3735 0.4426 0.5104 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fs1_y fs_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (-0.0157  0.0038  "CHN", place(se) size(small)) ///
text (0.0026 0.5177         , place(se) size(small)) ///
text (0 0.3735       , place(nw) size(small)) ///
text (0 0.3784  "BOL", place(nw) size(small)) ///
text (0 0.4426       , place(nw) size(small)) ///
text (0 0.4412  "ARG", place(nw) size(small)) ///
text (0 0.5104       , place(se) size(small)) ///
text (0 0.5014  "GHA", place(se) size(small)) ///
text (0.0198  1 "USA", place(n)  size(small))


**boone**
gen bon1_y=0 if id==31
replace bon1_y=0 if id==30
replace bon1_y=0 if id==12
replace bon1_y=0.0154 if id==13
replace bon1_y=-0.0206 if id==80
gen bon_1=0.2199 if id==31
replace bon_1=0.3792 if id==30
replace bon_1=0.6098 if id==12
replace bon_1=0.0038  if id==13
replace bon_1=1 if id==80

xtabond2 lnav_engpc c.fin_dev c.fin_dev#c.sc_right c.av_bon c.av_bon#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev,    lag(1 3))               gmm(c.fin_dev#c.sc_right, lag(1 2)orthogonal) ///
gmm(c.av_bon,     lag(1 4)orthogonal)     gmm(c.av_bon#c.sc_right,  lag(2 3)) ///
gmm(c.sc_right,   lag(1 1)) ///
gmm(c.lnav_gdp,   lag(3 3))    gmm(c.lnav_gdp#c.lnav_gdp,  lag(1 1) ) ///  
iv(ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small
margins, dydx(c.lnav_gdp)

/*Boone
找x軸的轉折點
margins, dydx(c.av_bon) at(sc_right=(0.213883 (0.000001) 0.213884))
margins, dydx(c.av_bon) at(sc_right=(0.615927 (0.000001) 0.615928))
找不同分位下的邊際效果
margins, dydx(c.av_bon) at(sc_right=0.0038)
margins, dydx(c.av_bon) at(sc_right=0.0479)
margins, dydx(c.av_bon) at(sc_right=0.1739)
margins, dydx(c.av_bon) at(sc_right=0.4412)
margins, dydx(c.av_bon) at(sc_right=0.9444)
margins, dydx(c.av_bon) at(sc_right=1)
margins, dydx(c.av_bon) at(sc_right=0.5177)
*/


margins, dydx(c.av_bon) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(b) Effect of Boone on energy use") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5177, lcolor(red) lpattern(dash)) ///
ytitle("∂ energy use / ∂ Boone") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0154 -0.0032 -0.0206, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5177 0.2139 0.3827 0.6159 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter bon1_y bon_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0154  0.0038  "CHN", place(ne) size(small)) ///
text (-0.0032 0.5177       , place(ne) size(small)) ///
text (0 0.2139       , place(sw) size(small)) ///
text (0 0.2189  "IDN", place(sw) size(small)) ///
text (0 0.3827       , place(sw) size(small)) ///
text (0 0.3792  "IND", place(sw) size(small)) ///
text (0 0.6159       , place(ne) size(small)) ///
text (0 0.6098  "CHL", place(ne) size(small)) ///
text (-0.0206 1 "USA", place(s)  size(small))


/**lerner**
xtabond2 lnav_engpc c.fin_dev c.fin_dev#c.sc_right c.av_lern c.av_lern#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev,    lag(1 2) orthogonal)   gmm(c.fin_dev#c.sc_right, lag(1 2)) ///
gmm(c.av_lern,    lag(1 1))              gmm(c.av_lern#c.sc_right, lag(3 3) orthogonal) ///
gmm(c.sc_right,   lag(2 3) orthogonal) ///
gmm(c.lnav_gdp,   lag(2 3))  gmm(c.lnav_gdp#c.lnav_gdp,  lag(1 2)) ///  
iv(ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small

margins, dydx(c.av_lern) at(sc_right=0.5123566)                                             
margins, dydx(c.av_lern) at(sc_right=(0 (0.01) 1))             
marginsplot, recast(line) recastci(rline) ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5123566, lcolor(red) lpattern(dash)) ///
ytitle("∂ Energy use / ∂ Lerner") ///
xtitle("political rights", margin(top)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick)) 
*/

**concerntration**
gen concn1_y=0 if id==29
replace concn1_y=0 if id==23
replace concn1_y=0 if id==33
replace concn1_y=0.0586 if id==13
replace concn1_y=-0.0178 if id==80
gen concn_1=0.6729 if id==29
replace concn_1=0.7708 if id==23
replace concn_1=0.8444 if id==33
replace concn_1=0.0038 if id==13
replace concn_1=1 if id==80

xtabond2 lnav_engpc c.fin_dev c.fin_dev#c.sc_right c.lnav_concn c.lnav_concn#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev,    lag(4 4) orthogonal)   gmm(c.fin_dev#c.sc_right,  lag(2 2)) ///
gmm(c.lnav_concn, lag(3 3) collapse)     gmm(c.lnav_concn#c.sc_right, lag(1 4)) ///
gmm(c.sc_right,   lag(1 2)) ///
gmm(c.lnav_gdp,   lag(2 3))    gmm(c.lnav_gdp#c.lnav_gdp,  lag(1 3)) ///  
iv(ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small

/*concerntration
找x軸的轉折點
margins, dydx(c.lnav_concn) at(sc_right=(0.70016 (0.00001) 0.70017))
margins, dydx(c.lnav_concn) at(sc_right=(0.85441 (0.00001) 0.85442))
找不同分位下的邊際效果
margins, dydx(c.lnav_concn) at(sc_right=0.0038)
margins, dydx(c.lnav_concn) at(sc_right=0.0479)
margins, dydx(c.lnav_concn) at(sc_right=0.1739)
margins, dydx(c.lnav_concn) at(sc_right=0.4412)
margins, dydx(c.lnav_concn) at(sc_right=0.9444)
margins, dydx(c.lnav_concn) at(sc_right=1)
margins, dydx(c.lnav_concn) at(sc_right=0.5177)
*/


margins, dydx(lnav_concn) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(e) Effect of concerntration on energy use") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5177, lcolor(red) lpattern(dash)) ///
ytitle("∂ energy use / ∂ concerntration") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0586 0.0192 -0.0178, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5177 0.7002 0.7679 0.8544 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter concn1_y concn_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0586  0.0038  "CHN", place(ne) size(small)) ///
text (0.0192  0.5177       , place(ne) size(small)) ///
text (0 0.7002       , place(sw) size(small)) ///
text (0 0.6729  "HUN", place(sw) size(small)) ///
text (0 0.7679       , place(ne) size(small)) ///
text (0 0.7708  "EST", place(ne) size(small)) ///
text (0 0.8544       , place(ne) size(small)) ///
text (0 0.8444  "ISR", place(ne) size(small)) ///
text (-0.0178 1 "USA", place(s)  size(small))



use "E:\隨身硬碟備份\E\TRY\findev_2017\Fin_Co2_pol_2018\dynamic gmm_4y\n82_4y_fin.dta",clear
set more off 
mata: mata set matafavor speed, perm
tsset id period
drop if id==45
drop if id==76


**household & enterprise**

gen hh1_y=0 if id==40
replace hh1_y=0 if id==12
replace hh1_y=0 if id==60
replace hh1_y=0.0265 if id==13
replace hh1_y=-0.0172 if id==80
gen hh_1=0.5249 if id==40
replace hh_1=0.6098 if id==12
replace hh_1=0.7476 if id==60
replace hh_1=0.0038 if id==13
replace hh_1=1 if id==80

gen fm1_y=0 if id==65
replace fm1_y=0 if id==33
replace fm1_y=-0.0373 if id==13
replace fm1_y=0.0068 if id==80
gen fm_1=0.6622 if id==65
replace fm_1=0.8444 if id==33
replace fm_1=0.0038 if id==13
replace fm_1=1 if id==80


xtabond2 lnav_engpc c.lnav_borhh c.lnav_borhh#c.sc_right c.lnav_borfm c.lnav_borfm#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.lnav_borhh, lag(1 3) collapse)         gmm(c.lnav_borhh#c.sc_right, lag(1 3) orthogonal) ///
gmm(c.lnav_borfm, lag(3 3) orthogonal)       gmm(c.lnav_borfm#c.sc_right, lag(2 2) orthogonal) ///
gmm(c.sc_right,   lag(2 2) collapse) ///
gmm(c.lnav_gdp,   lag(2 2))   gmm(c.lnav_gdp#c.lnav_gdp,   lag(1 2)) ///  
iv(ln_engpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small

/*household credit
找x軸的轉折點
margins, dydx(c.lnav_borhh) at(sc_right=(0.52562 (0.00001) 0.52563))
margins, dydx(c.lnav_borhh) at(sc_right=(0.71957 (0.00001) 0.71958))
找不同分位下的邊際效果
margins, dydx(c.lnav_borhh) at(sc_right=0.0038)
margins, dydx(c.lnav_borhh) at(sc_right=0.0479)
margins, dydx(c.lnav_borhh) at(sc_right=0.1739)
margins, dydx(c.lnav_borhh) at(sc_right=0.4412)
margins, dydx(c.lnav_borhh) at(sc_right=0.9444)
margins, dydx(c.lnav_borhh) at(sc_right=1)
margins, dydx(c.lnav_borhh) at(sc_right=0.5177)
*/

margins, dydx(lnav_borhh) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(b) Effect of household credit on energy use") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5177, lcolor(red) lpattern(dash)) ///
ytitle("∂ energy use / ∂ household credit") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0265 0.0040 -0.0172, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5177 0.5256 0.6026 0.7196 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter hh1_y hh_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0265  0.0042  "CHN", place(ne) size(small)) ///
text (0.0040  0.5177       , place(ne) size(small)) ///
text (0 0.5256       , place(sw) size(small)) ///
text (0 0.5249  "KOR", place(sw) size(small)) ///
text (0 0.6026       , place(ne) size(small)) ///
text (0 0.6098  "CHL", place(ne) size(small)) ///
text (0 0.7196       , place(ne) size(small)) ///
text (0 0.7476  "POL", place(ne) size(small)) ///
text (-0.0172 1 "USA", place(s)  size(small))

/*enterprise credit
找x軸的轉折點
margins, dydx(c.lnav_borfm) at(sc_right=(0.64787 (0.00001) 0.64788))
找不同分位下的邊際效果
margins, dydx(c.lnav_borfm) at(sc_right=0.0038)
margins, dydx(c.lnav_borfm) at(sc_right=0.0479)
margins, dydx(c.lnav_borfm) at(sc_right=0.1739)
margins, dydx(c.lnav_borfm) at(sc_right=0.4412)
margins, dydx(c.lnav_borfm) at(sc_right=0.9444)
margins, dydx(c.lnav_borfm) at(sc_right=1)
margins, dydx(c.lnav_borfm) at(sc_right=0.5177)
*/

margins, dydx(lnav_borfm) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(e) Effect of enterprise credit on energy use") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5177, lcolor(red) lpattern(dash)) ///
ytitle("∂ energy use / ∂ enterprise credit") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(-0.0373 -0.0136 0.0068, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5177 0.6478 0.8465 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fm1_y fm_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (-0.0373  0.0038  "CHN", place(se) size(small)) ///
text (-0.0136  0.5385       , place(nw) size(small)) ///
text (0 0.6478       , place(nw) size(small)) ///
text (0 0.6622  "SVK", place(nw) size(small)) ///
text (0 0.8465       , place(se) size(small)) ///
text (0 0.8444  "ISR", place(se) size(small)) ///
text (0.0068  1 "USA", place(n)  size(small))


